//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Data;
using System.Text;
using OpenLS.Chart.UI.Internals;

namespace OpenLS.Chart.UI
{
    class DataLabelConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            foreach (var obj in values)
            {
                if (obj == null)
                    return null;
            }
            if (values[1] is DataLabels)
            {
                var l = (DataLabels) values[1];
                var value = (ScatterValue) values[0];
                var sb = new StringBuilder();
                if (l.ValueVisible.GetValueOrDefault())
                {
                    string s;
                    if (l.Format != null)
                        s = l.Format.Format.GetFormattedValue(value.Y).ToString();
                    else
                    {
                        s = value.Y.ToString();
                    }
                    sb.Append(s);
                    sb.Append(l.Separator);
                }
                return sb.ToString();
            }
            throw new NotImplementedException();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
